"""
异常类模块 - 定义自定义异常类
"""

class FDASError(Exception):
    """基础异常类"""
    
    def __init__(self, message: str = ""):
        self.message = message
        super().__init__(self.message)
    
    def __str__(self) -> str:
        return f"{self.__class__.__name__}: {self.message}"

class ConfigError(FDASError):
    """配置错误"""
    pass

class DataError(FDASError):
    """数据错误"""
    pass

class DataFetchError(DataError):
    """数据获取错误"""
    pass

class APIError(FDASError):
    """API错误"""
    
    def __init__(self, message: str = "", status_code: int = None):
        self.status_code = status_code
        super().__init__(message)
    
    def __str__(self) -> str:
        if self.status_code:
            return f"{self.__class__.__name__} ({self.status_code}): {self.message}"
        return super().__str__()

class ValidationError(FDASError):
    """验证错误"""
    
    def __init__(self, message: str = "", field: str = None):
        self.field = field
        super().__init__(message)
    
    def __str__(self) -> str:
        if self.field:
            return f"{self.__class__.__name__} ({self.field}): {self.message}"
        return super().__str__()